﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;

namespace ZoomAtMouse
{
    public class KeyboardExtension : KeyProcessor
    {
        IWpfTextView _view;

        public KeyboardExtension(IWpfTextView view)
        {
            _view = view;
        }

        public override void KeyDown(System.Windows.Input.KeyEventArgs args)
        {
            switch (args.Key)
            {
                case System.Windows.Input.Key.LeftCtrl:
                case System.Windows.Input.Key.RightCtrl:
                    Keyboard.CtrlKeyDown = true;
                    Keyboard.ZoomLevelAtCtrlKeyDown = _view.ZoomLevel;
                    break;
                case System.Windows.Input.Key.LeftShift:
                case System.Windows.Input.Key.RightShift:
                    Keyboard.ShiftKeyDown = true;
                    Keyboard.ZoomLevelAtCtrlKeyDown = _view.ZoomLevel;
                    break;
            }

            base.KeyDown(args);
        }

        public override void KeyUp(System.Windows.Input.KeyEventArgs args)
        {
            switch (args.Key)
            {
                case System.Windows.Input.Key.LeftCtrl:
                case System.Windows.Input.Key.RightCtrl:
                    Keyboard.CtrlKeyDown = false;
                    break;
                case System.Windows.Input.Key.LeftShift:
                case System.Windows.Input.Key.RightShift:
                    Keyboard.ShiftKeyDown = false;
                    break;
            }

            base.KeyUp(args);
        }
    }
}
